<template>
  <!-- 机构列表页 -->
  <div>
       <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="渠道名称:">
                <el-input v-model="Mdate.name" placeholder="审批人"></el-input>
            </el-form-item>         
            <el-form-item>
                <el-button type="primary" @click="Mselect">查询</el-button>
            </el-form-item> 
        </el-form>
    <el-table v-if="tableData3.length>0" :data="tableData3" border style="width: 100%"   highlight-current-row
    @current-change="handleCurrentSelect">
      
      <el-table-column prop="ORGANIZATION_ID" label="渠道编号" width="180">
      </el-table-column>
      <el-table-column prop="ORGANIZATION_NAME" label="渠道名称" width="100">
      </el-table-column>
      <el-table-column prop="ORGANIZATION_CONTACTS" label="联系人" width="180">
      </el-table-column>
      <el-table-column prop="ORGANIZATION_TEL" label="联系电话" width="150">
      </el-table-column>
      <el-table-column prop="ORGANIZATION_EMAIL" label="邮箱" width="200">
      </el-table-column>
      <!-- <el-table-column prop="CUSTOM_EMAIL" label="渠道负责人" width="200">
                                                </el-table-column> -->
      <el-table-column prop="ORGANIZATION_LEVEL" label="星级" width="200">
      </el-table-column>
     
    </el-table>
    <div class="block">
      <el-pagination @current-change="handleCurrentChange" :current-page="currentPage" :page-size="10" layout="total, prev, pager, next" :total="pagecount">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import api from "@/js/api";
import getid from "@/js/getid";
export default {
  data() {
    return {
      pagecount: 1,
      currentPage: 1,
      tableData3: [],
      Sdate: {
        name: "",
        address: "",
        people: "",
        time: []
      },
      //多条件查询
      Mdate: {
        name: "",
        address: "",
        people: "",
        time: []
      }
    };
  },
  props: {
    Oid: {
      type: String,
      default: ""
    }
  },
  methods: {
    //
    handleCurrentChange(val) {
      this.currentPage = val;
      this.Mselect(true);
    },
    //选择
    handleCurrentSelect(val) {     
      if (val.ORGANIZATION_ID == this.Oid) {
        this.$notify.error({
          title: "失败",
          message: "推荐人不能为自己"
        });
        return;
      }
      this.$emit("selectSuccess", val);
    },
    goAddCommunication(cid) {
      let data = {
        id: cid,
        type: "渠道"
      };
      this.$emit("goAddCommunication", data);
    },
    goAddCustom(cid) {
      this.$emit("goAddCustom", cid);
    },
    goOrganizaitionEditer(id) {
      this.$emit("goOrganizaitionEditer", id);
    },
    //多条件查询
    Mselect(currentChange) {  
      let that = this;
      var data = {
        name: this.Mdate.name == "" ? null : this.Mdate.name,
        address: this.Mdate.name == "" ? null : this.Mdate.address,
        people: this.Mdate.name == "" ? null : this.Mdate.people
      };
      if (this.Mdate.time.length > 0) {
        data.startTime = getid.getDateString(this.Mdate.time[0]);
        data.endTime = getid.getDateString(this.Mdate.time[1]);
      } else {
        data.startTime = null;
        data.endTime = null;
      }
       if (!currentChange) {
        this.currentPage = 1;
      }
      data.pageIndex = this.currentPage;
      data.pageSize = 10;
      var role = sessionStorage.getItem("userRole");
      if (role == "销售助理" || role == "销售主管") {
        data.userId = null;
      } else {
        data.userId = sessionStorage.getItem("userId");
      }
      api.OrgnizationGetMutial(that, data, function(msg) {
        that.tableData3 = msg.Result;
        that.pagecount = msg.ListCount;
      });
    },
    //获取数据
    Getdata() {
      var role = sessionStorage.getItem("userRole");
      if (role == "销售助理" || role == "销售主管") {
        var data = {
          pageIndex: this.currentPage,
          pageSize: 10,
          userId: sessionStorage.getItem("userId")
        };
        let that = this;
        api.OrgnizationGetList(that, data, function(msg) {
          that.tableData3 = msg.Result;
          that.pagecount = msg.ListCount;
        });
      } else {
        var data = {
          pageIndex: this.currentPage,
          pageSize: 10,
          userId: sessionStorage.getItem("userId")
        };
        let that = this;
        api.OrgnizationGetUserList(that, data, function(msg) {
          that.tableData3 = msg.Result;
          that.pagecount = msg.ListCount;
        });
      }
    }
  },
  created() {
    this.currentPage = 1;
    this.Getdata();
  }
};
</script>
